module.exports = {
    prefix: "/bmob/",
    get: {
        "requestSmsCode/:params": {
            des: {
                name: "requestSmsCode",
                content: "获取短信验证码",
                params: [
                    {
                        key: "mobilePhoneNumber",
                        type: "Number|String"
                    },
                    {
                        params: "短信模块名称"
                    }
                ]
            },
            method: function* (params) {
                var self = this;
                print("获取短信验证码");
                var time = (new Date()).getTime();
                if ((time - (self.session[self.params.params] || 0)) < 180000) {
                    self.body = printError("每个号码每3分钟只能获取一次验证码");
                    return;
                }
                try {
                    var _obj = yield bmob.sms.requestSmsCode(self.request.query.mobile, self.params.params);
                    self.session[self.params.params] = time;
                    self.body = _obj;
                } catch (e) {
                    switch (e.code) {
                        case 10010:
                            self.body = printError("该手机号当天获取验证码达到上限，每天只能获取10次,每小时获取5次");
                            break;
                        default:
                            self.body = printError("短信发送错误，请稍后重试");
                            break;
                    };
                };
            }
        },
    },
    post: {
        "imageThumb": {
            des: {
                name: "requestImageThumbnail",
                content: "获取缩略图",
                params: [
                    {
                        key: "option",
                        type: "JSON"
                    }
                ]
            },
            method: function* (next) {
                var self = this;
                print("Bmob获取缩略图");
                // option参数参考/tools/Bmob.t.js  image.thumb
                try {
                    var option = self.request.body;
                    printData(option);
                    var _obj = yield bmob.image.thumb(option);
                    self.body = _obj;
                } catch (e) {
                    self.body = printError(e);
                };
            }
        },
    }
}